package com.sgb.kjwl.view.ui.adapter.home;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.BuildEntity;
import com.sgb.kjwl.model.entity.TalentEntity;
import com.sgb.kjwl.view.widget.FlowLayout;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;
import com.swgk.core.util.MDateUtil;

import java.util.List;

public class TalentAdapter extends BaseRecycleAdapter<TalentEntity> {

    private TextView areaView;
    private TextView timeView;
    private FlowLayout flSkills;
    private Context context;

    public TalentAdapter(Context context, List<TalentEntity> datas) {
        super(context, R.layout.item_talent, datas);
        this.context = context;
    }

    @Override
    public void convert(ItemViewHolder holder, final TalentEntity entity) {
        holder.setBinding(BR.viewModel, entity);
        areaView = holder.getItem().findViewById(R.id.area_view);
        areaView.setText("所在地：" + entity.getArea());
        timeView = holder.getItem().findViewById(R.id.time_view);

        flSkills = holder.getItem().findViewById(R.id.fl_skills);
        LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        layoutParams.setMargins(5, 3, 5, 3);
        if (flSkills != null) {
            flSkills.removeAllViews();
        }
        String[] split = entity.getSkill().split("、");
        for (int i = 0; i < split.length; i++) {
            TextView tv = new TextView(context);
            tv.setTextSize(12);
            tv.setPadding(28, 5, 28, 5);
            tv.setText(split[i]);
            tv.setTextColor(context.getResources().getColor(R.color.color_0286DF));
            tv.setMaxEms(10);
            tv.setSingleLine();
            tv.setBackgroundResource(R.drawable.corner_blue_shape);
            tv.setLayoutParams(layoutParams);
            flSkills.addView(tv, layoutParams);
        }

        try {
            timeView.setText(MDateUtil.getByTimestamp(Long.parseLong(entity.getUpdateTime()), MDateUtil.Format.FORMART5.name));
        } catch (NumberFormatException e) {

        }
    }

}
